const User = require('./User');
const Transaction = require('./Transaction');
const StoredWine = require('./StoredWine');

// 定义模型关联关系
// 用户与交易记录：一对多
User.hasMany(Transaction, { foreignKey: 'userId', as: 'transactions' });
Transaction.belongsTo(User, { foreignKey: 'userId', as: 'user' });

// 操作员与交易记录：一对多
User.hasMany(Transaction, { foreignKey: 'operatorId', as: 'operatedTransactions' });
Transaction.belongsTo(User, { foreignKey: 'operatorId', as: 'operator' });

// 用户与寄存酒：一对多
User.hasMany(StoredWine, { foreignKey: 'userId', as: 'storedWines' });
StoredWine.belongsTo(User, { foreignKey: 'userId', as: 'user' });

module.exports = {
  User,
  Transaction,
  StoredWine
};
